/*******************************************************************************
*  file    : uzdatagetter.hpp
*  created : 05.06.2013
*  author  : Slyshyk Oleksiy (alexSlyshyk@gmail.com)
*******************************************************************************/

#ifndef UZDATAGETTER_HPP
#define UZDATAGETTER_HPP

#include "uzdatagetter_global.hpp"
#include "traindata.hpp"
#include <QObject>
#include <QDateTime>
#include <QMap>
#include <QList>
#include <QVector>

class QNetworkAccessManager;

struct UZDATAGETTERSHARED_EXPORT TicketInfo
{
    int          id;// для идентификации запроса -должен быть уникальнвм
    QByteArray   from;
    QByteArray   from_id;
    QByteArray   to;
    QByteArray   to_id;
    QByteArray   date;
};

struct UZDATAGETTERSHARED_EXPORT CityData
{
    QString name;
    QString id;
};

class UZDATAGETTERSHARED_EXPORT UzDataGetter : public QObject
{
    Q_OBJECT
public:
    UzDataGetter(QObject* parent);
    QVector<CityData>  cities(const QString& key)const;
    QVector<TrainData> trainData(int key) const ;
public slots:
    void requestCities(const QString& nm);
    void requestTicketInfo(TicketInfo ti);

    void requestCoaches();
private slots:
    void replyCities();
    void replyTicketInfo();

    void replyCoaches();
signals:
    void citiesLoaded(const QString&);
    void trainDataReady(int);
private:
    QNetworkAccessManager*           m_accessManager;
    ///в указателе - первые 2 буквы города в верхнем регистре
    QMap<QString, QVector<CityData>> m_cities;

    QMap<int, QVector<TrainData>>    m_trainData;
};

#endif // UZDATAGETTER_HPP
